import matplotlib as mat
import csv
import numpy as np
import matplotlib.pyplot as plt
from math import log10
# import xlrd
# plt.rcParams['font.sans-serif']=['SimHei']
# plt.rcParams['axes.unicode_minus']=False
xge=1

seachfile=open("search_Lx38erg_beta1.out",'r')
data_source=csv.reader(seachfile)
result=seachfile.readlines()
seachfile.close()
timespan=[0]*len(result)
xdata=[0]*len(result)

xindex=0
xstep=1

xlog=False

for i in range(len(result)):
    result[i]=result[i].split()
    result[i] = list(map(float, result[i]))
    timespan[i]=result[i][7]-result[i][6]
    if(xlog):
        xdata[i]=log10(result[i][xindex])
    else:
        xdata[i]=(result[i][xindex])
    


del result

x=min(xdata)

xrange=[]
xrangestr=[]

while (x<max(xdata)):
    
    xrange.append(x)
    xrangestr.append("%.0f" % x)
    x=x+xstep*xge


datamap=np.zeros((len(xrange)*xge))
xnpdata=np.array(xdata)

xwei=((xnpdata-min(xdata))/xstep).astype(int)

for i in range(len(xdata)):
    if(timespan[i]>1):continue
    datamap[xwei[i]]=datamap[xwei[i]]+timespan[i]


# searchxls=xlrd.open_workbook("search20200325beta1,xls")

datamap=datamap/(np.max(datamap))




fig, ax = plt.subplots()
ax.bar(xrangestr,datamap)
# plt.yticks(range(1,np.max(xwei)),xrangestr)

# plt.xlabel('campanion mass / Msun')
# plt.ylabel('orbit period / day')

# plt.xlabel('m1 / Msun')
# plt.ylabel('m2 / Msun')
plt.title('')
plt.show()
